<?php

// $Id$

require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/ci/tcms_ci_type_dbc.class.php');
require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/ci/tcms_ci_deleter.class.php');
require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/ci/tcms_ci_type_attr_dbc.class.php');


class TCMS_CI_Type_Deleter extends Tangra_Class {
	public static function delete(DB_Connection $dbc, $id, $hidden_inc_dir, $current_user_id) {
		tangra_if_not_int_throw_e($id);

		TCMS_CI_Type_Deleter::delete_cis_for_type($dbc, $id, $hidden_inc_dir, $current_user_id);
		TCMS_CI_Type_Attr_DBC::delete_all_for_type($dbc, $id);
		TCMS_CI_Type_DBC::delete($dbc, $id);
	}


	private static function delete_cis_for_type(DB_Connection $dbc, $type_id, $hidden_inc_dir, $current_user_id) {
		$sql = TCMS_CI_DBC::get_sql_select_all_ids_for_type($dbc, $type_id);
		$rez = $dbc->execute($sql);
		while($rez_obj = $rez->fetch_object()) {
			TCMS_CI_Deleter::delete($dbc, $rez_obj->ID, $hidden_inc_dir, $current_user_id);
		}
	}
}